package com.zxn.ssyx.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zxn.ssyx.mapper.CategoryMapper;
import com.zxn.ssyx.model.product.Category;
import com.zxn.ssyx.service.CategoryService;
import com.zxn.ssyx.vo.product.CategoryQueryVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {
    @Autowired
    private CategoryMapper categoryMapper;
    @Override
    public IPage<Category> selectPage(Page<Category> pageParam, CategoryQueryVo categoryQueryVo) {
        LambdaQueryWrapper<Category> lqw = new LambdaQueryWrapper<>();
        if (categoryQueryVo.getName() != null){
            lqw.like(Category::getName,categoryQueryVo.getName());
        }
        return categoryMapper.selectPage(pageParam,lqw);
    }

    @Override
    public List<Category> findAllList() {
        LambdaQueryWrapper<Category> lqw = new LambdaQueryWrapper<>();
        lqw.orderByAsc(Category::getSort);
        return categoryMapper.selectList(lqw);
    }
}
